﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using TarreOA.TarreOAModels;

namespace TarreOA.TarreOADAL
{
    public class PublicCommunicationGroupLinkMantbDAO
    {
        /// <summary>
        /// 为指定通讯组添加联系人
        /// </summary>
        /// <param name="comGroupId"></param>
        /// <param name="groupLinkManName"></param>
        /// <param name="groupLinkManSec"></param>
        /// <param name="groupLinkManBirthday"></param>
        /// <param name="groupLinkManName2"></param>
        /// <param name="groupLinkManDurty"></param>
        /// <param name="groupLinkManUnitName"></param>
        /// <param name="groupLinkManUnitAddress"></param>
        /// <param name="groupLinkManUnitTelephone"></param>
        /// <param name="groupLinkManUnitFacsimile"></param>
        /// <param name="groupLinkManHomeAddress"></param>
        /// <param name="groupLinkManHomeTelephone"></param>
        /// <param name="groupLinkManHandset"></param>
        /// <param name="groupLinkManEmail"></param>
        /// <param name="groupLinkManOicq"></param>
        /// <param name="groupLinkManMsn"></param>
        /// <param name="groupLinkManRemark"></param>
        /// <returns></returns>
        public int saveComGroupLinkManInfo(int comGroupId, string groupLinkManName, int groupLinkManSec, DateTime groupLinkManBirthday
            , string groupLinkManName2, string groupLinkManDurty, string groupLinkManUnitName, string groupLinkManUnitAddress
            , string groupLinkManUnitTelephone, string groupLinkManUnitFacsimile, string groupLinkManHomeAddress
            , string groupLinkManHomeTelephone, string groupLinkManHandset, string groupLinkManEmail, string groupLinkManOicq
            , string groupLinkManMsn, string groupLinkManRemark)
        {
            int count = 0;
            SqlConnection sqlConn = null;
            SqlCommand sqlCmd = null;
            try
            {
                sqlConn = SQLManager.GetConn();
                sqlConn.Open();
                string sql = "insert into PublicCommunicationGroupLinkMan values(@cgid, @glmn, @glms, @glmb, @glmn2, @glmd, @glmun" +
                    ", @glmua, @glmut, @glmuf, @glmha, @glmht, @glmhs, @glme, @glmO, @glmM, @glmR)";
                sqlCmd = new SqlCommand(sql, sqlConn);
                sqlCmd.Parameters.Add(new SqlParameter("@cgid", comGroupId));
                sqlCmd.Parameters.Add(new SqlParameter("@glmn", groupLinkManName));
                sqlCmd.Parameters.Add(new SqlParameter("@glms", groupLinkManSec));
                sqlCmd.Parameters.Add(new SqlParameter("@glmb", groupLinkManBirthday));
                sqlCmd.Parameters.Add(new SqlParameter("@glmn2", groupLinkManName2));
                sqlCmd.Parameters.Add(new SqlParameter("@glmd", groupLinkManDurty));
                sqlCmd.Parameters.Add(new SqlParameter("@glmun", groupLinkManUnitName));
                sqlCmd.Parameters.Add(new SqlParameter("@glmua", groupLinkManUnitAddress));
                sqlCmd.Parameters.Add(new SqlParameter("@glmut", groupLinkManUnitTelephone));
                sqlCmd.Parameters.Add(new SqlParameter("@glmuf", groupLinkManUnitFacsimile));
                sqlCmd.Parameters.Add(new SqlParameter("@glmha", groupLinkManHomeAddress));
                sqlCmd.Parameters.Add(new SqlParameter("@glmht", groupLinkManHomeTelephone));
                sqlCmd.Parameters.Add(new SqlParameter("@glmhs", groupLinkManHandset));
                sqlCmd.Parameters.Add(new SqlParameter("@glme", groupLinkManEmail));
                sqlCmd.Parameters.Add(new SqlParameter("@glmO", groupLinkManOicq));
                sqlCmd.Parameters.Add(new SqlParameter("@glmM", groupLinkManMsn));
                sqlCmd.Parameters.Add(new SqlParameter("@glmR", groupLinkManRemark));
                count = sqlCmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sqlConn != null && sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
            return count;
        }

        /// <summary>
        /// 根据通讯组编号查找该通讯组的联系人信息
        /// </summary>
        /// <param name="cgid"></param>
        /// <returns></returns>
        public List<PublicCommunicationGroupLinkMantb> findByComGroupId(int cgid)
        {
            List<PublicCommunicationGroupLinkMantb> list = null;
            SqlConnection sqlConn = null;
            SqlCommand sqlCmd = null;
            SqlDataReader sqlDr = null;
            try
            {
                sqlConn = SQLManager.GetConn();
                sqlConn.Open();
                string sql = "select * from PublicCommunicationGroupLinkMan where ComGroupId = @cgid";
                sqlCmd = new SqlCommand(sql, sqlConn);
                sqlCmd.Parameters.Add(new SqlParameter("@cgid", cgid));
                sqlDr = sqlCmd.ExecuteReader();
                if (sqlDr.HasRows)
                {
                    list = new List<PublicCommunicationGroupLinkMantb>();
                    UserDAO userDAO = new UserDAO();
                    PublicCommunicationGrouptbDAO pcgDAO = new PublicCommunicationGrouptbDAO();
                    while (sqlDr.Read())
                    {
                        PublicCommunicationGroupLinkMantb pcgLman = new PublicCommunicationGroupLinkMantb();
                        pcgLman.GroupLinkManId = (int)sqlDr["GroupLinkManId"];
                        pcgLman.ComGroup = pcgDAO.findById((int)sqlDr["ComGroupId"]);
                        pcgLman.GroupLinkManName = sqlDr["GroupLinkManName"].ToString();
                        pcgLman.GroupLinkManSec = (int)sqlDr["GroupLinkManSec"];
                        pcgLman.GroupLinkManBirthday = (DateTime)sqlDr["GroupLinkManBirthday"];
                        pcgLman.GroupLinkManName2 = sqlDr["GroupLinkManName2"].ToString();
                        pcgLman.GroupLinkManDuty = sqlDr["GroupLinkManDuty"].ToString();
                        pcgLman.GroupLinkManUnitName = sqlDr["GroupLinkManUnitName"].ToString();
                        pcgLman.GroupLinkManUnitAddress = sqlDr["GroupLinkManUnitAddress"].ToString();
                        pcgLman.GroupLinkManUnitTelephone = sqlDr["GroupLinkManUnitTelephone"].ToString();
                        pcgLman.GroupLinkManUnitFacsimile = sqlDr["GroupLinkManUnitFacsimile"].ToString();
                        pcgLman.GroupLinkManHomeAddress = sqlDr["GroupLinkManHomeAddress"].ToString();
                        pcgLman.GroupLinkManHomeTelephone = sqlDr["GroupLinkManHomeTelephone"].ToString();
                        pcgLman.GroupLinkManHandset = sqlDr["GroupLinkManHandset"].ToString();
                        pcgLman.GroupLinkManEmail = sqlDr["GroupLinkManEmail"].ToString();
                        pcgLman.GroupLinkManOicq = sqlDr["GroupLinkManOicq"].ToString();
                        pcgLman.GroupLinkManMsn = sqlDr["GroupLinkManMsn"].ToString();
                        pcgLman.GroupLinkManRemark = sqlDr["GroupLinkManRemark"].ToString();
                        list.Add(pcgLman);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sqlDr != null)
                {
                    sqlDr.Close();
                    sqlDr.Dispose();
                }
                if (sqlConn != null && sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
            return list;
        }

        /// <summary>
        ///  根据通讯人编号查找通讯人信息
        /// </summary>
        /// <param name="cglmId"></param>
        /// <returns></returns>
        public PublicCommunicationGroupLinkMantb findByCglmId(int cglmId)
        {
            PublicCommunicationGroupLinkMantb pcgLman = null;
            SqlConnection sqlConn = null;
            SqlCommand sqlCmd = null;
            SqlDataReader sqlDr = null;
            try
            {
                sqlConn = SQLManager.GetConn();
                sqlConn.Open();
                string sql = "select * from PublicCommunicationGroupLinkMan where GroupLinkManId = @cglmId";
                sqlCmd = new SqlCommand(sql, sqlConn);
                sqlCmd.Parameters.Add(new SqlParameter("@cglmId", cglmId));
                sqlDr = sqlCmd.ExecuteReader();
                if (sqlDr.HasRows)
                {
                    pcgLman = new PublicCommunicationGroupLinkMantb();
                    PublicCommunicationGrouptbDAO pcgDAO = new PublicCommunicationGrouptbDAO();
                    sqlDr.Read();
                    pcgLman.GroupLinkManId = (int)sqlDr["GroupLinkManId"];
                    pcgLman.ComGroup = pcgDAO.findById((int)sqlDr["ComGroupId"]);
                    pcgLman.GroupLinkManName = sqlDr["GroupLinkManName"].ToString();
                    pcgLman.GroupLinkManSec = (int)sqlDr["GroupLinkManSec"];
                    pcgLman.GroupLinkManBirthday = (DateTime)sqlDr["GroupLinkManBirthday"];
                    pcgLman.GroupLinkManName2 = sqlDr["GroupLinkManName2"].ToString();
                    pcgLman.GroupLinkManDuty = sqlDr["GroupLinkManDuty"].ToString();
                    pcgLman.GroupLinkManUnitName = sqlDr["GroupLinkManUnitName"].ToString();
                    pcgLman.GroupLinkManUnitAddress = sqlDr["GroupLinkManUnitAddress"].ToString();
                    pcgLman.GroupLinkManUnitTelephone = sqlDr["GroupLinkManUnitTelephone"].ToString();
                    pcgLman.GroupLinkManUnitFacsimile = sqlDr["GroupLinkManUnitFacsimile"].ToString();
                    pcgLman.GroupLinkManHomeAddress = sqlDr["GroupLinkManHomeAddress"].ToString();
                    pcgLman.GroupLinkManHomeTelephone = sqlDr["GroupLinkManHomeTelephone"].ToString();
                    pcgLman.GroupLinkManHandset = sqlDr["GroupLinkManHandset"].ToString();
                    pcgLman.GroupLinkManEmail = sqlDr["GroupLinkManEmail"].ToString();
                    pcgLman.GroupLinkManOicq = sqlDr["GroupLinkManOicq"].ToString();
                    pcgLman.GroupLinkManMsn = sqlDr["GroupLinkManMsn"].ToString();
                    pcgLman.GroupLinkManRemark = sqlDr["GroupLinkManRemark"].ToString();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sqlDr != null)
                {
                    sqlDr.Close();
                    sqlDr.Dispose();
                }
                if (sqlConn != null && sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
            return pcgLman;
        }

        /// <summary>
        /// 根据通讯人编号删除通讯人信息
        /// </summary>
        /// <param name="pcglmId"></param>
        /// <returns></returns>
        public int delByPcglmid(int pcglmId)
        {
            int count = 0;
            SqlConnection sqlConn = null;
            SqlCommand sqlCmd = null;
            try
            {
                sqlConn = SQLManager.GetConn();
                sqlConn.Open();
                string sql = "delete from PublicCommunicationGroupLinkMan where GroupLinkManId = @pcglmId";
                sqlCmd = new SqlCommand(sql, sqlConn);
                sqlCmd.Parameters.Add(new SqlParameter("@pcglmId", pcglmId));
                count = sqlCmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sqlConn != null && sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
            return count;
        }

        /// <summary>
        /// 根据通讯组联系人编号更改联系人信息
        /// </summary>
        /// <param name="cgLmid"></param>
        /// <param name="cgid"></param>
        /// <param name="cgLmName"></param>
        /// <param name="cgLmSec"></param>
        /// <param name="cgLmBirthday"></param>
        /// <param name="cgLmName2"></param>
        /// <param name="cgLmDuty"></param>
        /// <param name="cgLmUnitName"></param>
        /// <param name="cgLmUnitAddress"></param>
        /// <param name="cgLmUnitTelephone"></param>
        /// <param name="cgLmUnitFacsimile"></param>
        /// <param name="cgLmHomeAddress"></param>
        /// <param name="cgLmHomeTelephone"></param>
        /// <param name="cgLmHandset"></param>
        /// <param name="cgLmEmail"></param>
        /// <param name="cgLmOicq"></param>
        /// <param name="cgLmMsn"></param>
        /// <param name="cgLmRemark"></param>
        /// <returns></returns>
        public int updateComGroupLinkManInfoByGroupLinkManId(int cgLmid, int cgid, string cgLmName, int cgLmSec, DateTime cgLmBirthday,
            string cgLmName2, string cgLmDuty, string cgLmUnitName, string cgLmUnitAddress, string cgLmUnitTelephone,
            string cgLmUnitFacsimile, string cgLmHomeAddress, string cgLmHomeTelephone, string cgLmHandset, string cgLmEmail,
            string cgLmOicq, string cgLmMsn, string cgLmRemark)
        {
            int count = 0;
            SqlConnection sqlConn = null;
            SqlCommand sqlCmd = null;
            try
            {
                sqlConn = SQLManager.GetConn();
                sqlConn.Open();
                string sql = "update PublicCommunicationGroupLinkMan set ComGroupId = @cgid, GroupLinkManName = @cgLmName, "
                    + " GroupLinkManSec = @cgLmSec, GroupLinkManBirthday = @cgLmBirthday, GroupLinkManName2 = @cgLmName2,"
                    + " GroupLinkManDuty = @cgLmDuty, GroupLinkManUnitName = @cgLmUnitName, GroupLinkManUnitAddress = @cgLmUnitAddress,"
                    + " GroupLinkManUnitTelephone = @cgLmUnitTelephone, GroupLinkManUnitFacsimile = @cgLmUnitFacsimile, GroupLinkManHomeAddress = @cgLmHomeAddress"
                    + ", GroupLinkManHomeTelephone = @cgLmHomeTelephone, GroupLinkManHandset = @cgLmHandset, GroupLinkManEmail = @cgLmEmail,"
                    + " GroupLinkManOicq = @cgLmOicq, GroupLinkManMsn = @cgLmMsn, GroupLinkManRemark = @cgLmRemark where GroupLinkManId = @cgLmid";
                sqlCmd = new SqlCommand(sql, sqlConn);
                sqlCmd.Parameters.Add(new SqlParameter("@cgid", cgid));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmName", cgLmName));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmSec", cgLmSec));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmBirthday", cgLmBirthday));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmName2", cgLmName2));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmDuty", cgLmDuty));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmUnitName", cgLmUnitName));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmUnitAddress", cgLmUnitAddress));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmUnitTelephone", cgLmUnitTelephone));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmUnitFacsimile", cgLmUnitFacsimile));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmHomeAddress", cgLmHomeAddress));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmHomeTelephone", cgLmHomeTelephone));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmHandset", cgLmHandset));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmEmail", cgLmEmail));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmOicq", cgLmOicq));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmMsn", cgLmMsn));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmRemark", cgLmRemark));
                sqlCmd.Parameters.Add(new SqlParameter("@cgLmid", cgLmid));
                count = sqlCmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sqlConn != null && sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
            return count;
        }

        /// <summary>
        /// 根据用户的单位关键字查找用户联系人信息
        /// </summary>
        /// <param name="lmUnitName"></param>
        /// <returns></returns>
        public List<PublicCommunicationGroupLinkMantb> findByLinkManUnitName(string lmUnitName)
        {
            List<PublicCommunicationGroupLinkMantb> list = null;
            SqlConnection sqlConn = null;
            SqlCommand sqlCmd = null;
            SqlDataReader sqlDr = null;
            try
            {
                sqlConn = SQLManager.GetConn();
                sqlConn.Open();
                string sql = "select * from PublicCommunicationGroupLinkMan where GroupLinkManUnitName like @lmName";
                sqlCmd = new SqlCommand(sql, sqlConn);
                sqlCmd.Parameters.Add(new SqlParameter("@lmName", "%" + lmUnitName + "%"));
                sqlDr = sqlCmd.ExecuteReader();
                if (sqlDr.HasRows)
                {
                    list = new List<PublicCommunicationGroupLinkMantb>();
                    UserDAO userDAO = new UserDAO();
                    PublicCommunicationGrouptbDAO pcgDAO = new PublicCommunicationGrouptbDAO();
                    while (sqlDr.Read())
                    {
                        PublicCommunicationGroupLinkMantb pcgLman = new PublicCommunicationGroupLinkMantb();
                        pcgLman.GroupLinkManId = (int)sqlDr["GroupLinkManId"];
                        pcgLman.ComGroup = pcgDAO.findById((int)sqlDr["ComGroupId"]);
                        pcgLman.GroupLinkManName = sqlDr["GroupLinkManName"].ToString();
                        pcgLman.GroupLinkManSec = (int)sqlDr["GroupLinkManSec"];
                        pcgLman.GroupLinkManBirthday = (DateTime)sqlDr["GroupLinkManBirthday"];
                        pcgLman.GroupLinkManName2 = sqlDr["GroupLinkManName2"].ToString();
                        pcgLman.GroupLinkManDuty = sqlDr["GroupLinkManDuty"].ToString();
                        pcgLman.GroupLinkManUnitName = sqlDr["GroupLinkManUnitName"].ToString();
                        pcgLman.GroupLinkManUnitAddress = sqlDr["GroupLinkManUnitAddress"].ToString();
                        pcgLman.GroupLinkManUnitTelephone = sqlDr["GroupLinkManUnitTelephone"].ToString();
                        pcgLman.GroupLinkManUnitFacsimile = sqlDr["GroupLinkManUnitFacsimile"].ToString();
                        pcgLman.GroupLinkManHomeAddress = sqlDr["GroupLinkManHomeAddress"].ToString();
                        pcgLman.GroupLinkManHomeTelephone = sqlDr["GroupLinkManHomeTelephone"].ToString();
                        pcgLman.GroupLinkManHandset = sqlDr["GroupLinkManHandset"].ToString();
                        pcgLman.GroupLinkManEmail = sqlDr["GroupLinkManEmail"].ToString();
                        pcgLman.GroupLinkManOicq = sqlDr["GroupLinkManOicq"].ToString();
                        pcgLman.GroupLinkManMsn = sqlDr["GroupLinkManMsn"].ToString();
                        pcgLman.GroupLinkManRemark = sqlDr["GroupLinkManRemark"].ToString();
                        list.Add(pcgLman);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sqlDr != null)
                {
                    sqlDr.Close();
                    sqlDr.Dispose();
                }
                if (sqlConn != null && sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
            return list;
        }

         /// <summary>
        /// 根据联系人生日查询当前用户的联系人
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public List<PublicCommunicationGroupLinkMantb> findByBirthday(string startDate, string endDate)
        {
            List<PublicCommunicationGroupLinkMantb> list = null;
            SqlConnection sqlConn = null;
            SqlCommand sqlCmd = null;
            SqlDataReader sqlDr = null;
            try
            {
                sqlConn = SQLManager.GetConn();
                sqlConn.Open();
                string sql = "select * from PublicCommunicationGroupLinkMan where GroupLinkManBirthday > @startDate and GroupLinkManBirthday < @endDate";
                sqlCmd = new SqlCommand(sql, sqlConn);
                sqlCmd.Parameters.Add(new SqlParameter("@startDate", startDate));
                sqlCmd.Parameters.Add(new SqlParameter("@endDate", endDate));
                sqlDr = sqlCmd.ExecuteReader();
                if (sqlDr.HasRows)
                {
                    list = new List<PublicCommunicationGroupLinkMantb>();
                    UserDAO userDAO = new UserDAO();
                    PublicCommunicationGrouptbDAO pcgDAO = new PublicCommunicationGrouptbDAO();
                    while (sqlDr.Read())
                    {
                        PublicCommunicationGroupLinkMantb pcgLman = new PublicCommunicationGroupLinkMantb();
                        pcgLman.GroupLinkManId = (int)sqlDr["GroupLinkManId"];
                        pcgLman.ComGroup = pcgDAO.findById((int)sqlDr["ComGroupId"]);
                        pcgLman.GroupLinkManName = sqlDr["GroupLinkManName"].ToString();
                        pcgLman.GroupLinkManSec = (int)sqlDr["GroupLinkManSec"];
                        pcgLman.GroupLinkManBirthday = (DateTime)sqlDr["GroupLinkManBirthday"];
                        pcgLman.GroupLinkManName2 = sqlDr["GroupLinkManName2"].ToString();
                        pcgLman.GroupLinkManDuty = sqlDr["GroupLinkManDuty"].ToString();
                        pcgLman.GroupLinkManUnitName = sqlDr["GroupLinkManUnitName"].ToString();
                        pcgLman.GroupLinkManUnitAddress = sqlDr["GroupLinkManUnitAddress"].ToString();
                        pcgLman.GroupLinkManUnitTelephone = sqlDr["GroupLinkManUnitTelephone"].ToString();
                        pcgLman.GroupLinkManUnitFacsimile = sqlDr["GroupLinkManUnitFacsimile"].ToString();
                        pcgLman.GroupLinkManHomeAddress = sqlDr["GroupLinkManHomeAddress"].ToString();
                        pcgLman.GroupLinkManHomeTelephone = sqlDr["GroupLinkManHomeTelephone"].ToString();
                        pcgLman.GroupLinkManHandset = sqlDr["GroupLinkManHandset"].ToString();
                        pcgLman.GroupLinkManEmail = sqlDr["GroupLinkManEmail"].ToString();
                        pcgLman.GroupLinkManOicq = sqlDr["GroupLinkManOicq"].ToString();
                        pcgLman.GroupLinkManMsn = sqlDr["GroupLinkManMsn"].ToString();
                        pcgLman.GroupLinkManRemark = sqlDr["GroupLinkManRemark"].ToString();
                        list.Add(pcgLman);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sqlDr != null)
                {
                    sqlDr.Close();
                    sqlDr.Dispose();
                }
                if (sqlConn != null && sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
            return list;
        }

        /// <summary>
        /// 根据联系人姓名查找当前用户的联系人信息
        /// </summary>
        /// <param name="lmName"></param>
        /// <returns></returns>
        public List<PublicCommunicationGroupLinkMantb> findByLinkManName(string lmName)
        {
            List<PublicCommunicationGroupLinkMantb> list = null;
            SqlConnection sqlConn = null;
            SqlCommand sqlCmd = null;
            SqlDataReader sqlDr = null;
            try
            {
                sqlConn = SQLManager.GetConn();
                sqlConn.Open();
                string sql = "select * from PublicCommunicationGroupLinkMan where GroupLinkManName like @lmName";
                sqlCmd = new SqlCommand(sql, sqlConn);
                sqlCmd.Parameters.Add(new SqlParameter("@lmName", "%" + lmName + "%"));
                sqlDr = sqlCmd.ExecuteReader();
                if (sqlDr.HasRows)
                {
                    list = new List<PublicCommunicationGroupLinkMantb>();
                    PublicCommunicationGrouptbDAO pcgDAO = new PublicCommunicationGrouptbDAO();
                    while (sqlDr.Read())
                    {
                        PublicCommunicationGroupLinkMantb pcgLman = new PublicCommunicationGroupLinkMantb();
                        pcgLman.GroupLinkManId = (int)sqlDr["GroupLinkManId"];
                        pcgLman.ComGroup = pcgDAO.findById((int)sqlDr["ComGroupId"]);
                        pcgLman.GroupLinkManName = sqlDr["GroupLinkManName"].ToString();
                        pcgLman.GroupLinkManSec = (int)sqlDr["GroupLinkManSec"];
                        pcgLman.GroupLinkManBirthday = (DateTime)sqlDr["GroupLinkManBirthday"];
                        pcgLman.GroupLinkManName2 = sqlDr["GroupLinkManName2"].ToString();
                        pcgLman.GroupLinkManDuty = sqlDr["GroupLinkManDuty"].ToString();
                        pcgLman.GroupLinkManUnitName = sqlDr["GroupLinkManUnitName"].ToString();
                        pcgLman.GroupLinkManUnitAddress = sqlDr["GroupLinkManUnitAddress"].ToString();
                        pcgLman.GroupLinkManUnitTelephone = sqlDr["GroupLinkManUnitTelephone"].ToString();
                        pcgLman.GroupLinkManUnitFacsimile = sqlDr["GroupLinkManUnitFacsimile"].ToString();
                        pcgLman.GroupLinkManHomeAddress = sqlDr["GroupLinkManHomeAddress"].ToString();
                        pcgLman.GroupLinkManHomeTelephone = sqlDr["GroupLinkManHomeTelephone"].ToString();
                        pcgLman.GroupLinkManHandset = sqlDr["GroupLinkManHandset"].ToString();
                        pcgLman.GroupLinkManEmail = sqlDr["GroupLinkManEmail"].ToString();
                        pcgLman.GroupLinkManOicq = sqlDr["GroupLinkManOicq"].ToString();
                        pcgLman.GroupLinkManMsn = sqlDr["GroupLinkManMsn"].ToString();
                        pcgLman.GroupLinkManRemark = sqlDr["GroupLinkManRemark"].ToString();
                        list.Add(pcgLman);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sqlDr != null)
                {
                    sqlDr.Close();
                    sqlDr.Dispose();
                }
                if (sqlConn != null && sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
            return list;
        }
    }

}
